package com.mice.game.trigger
{
	import com.mice.game.core.Player;

	/**
	 * 精力管理.对玩家/ai精力进行恢复
	 */	
	public class EnergyTrigger{
		private static var _instance:EnergyTrigger;
		
		public var player:Player;
		public var ai:Player;
		
		private var _playerTick:int = 0;
		private var _aiTick:int = 0;
		
		public function EnergyTrigger(){}
		
		public static function get instance():EnergyTrigger{
			if (_instance == null)
				_instance = new EnergyTrigger();
			return _instance;
		}
		
		public function reset():void{
			_playerTick = 0;
			_aiTick = 0;
		}
		
		public function update():void{
			_playerTick++;
			_aiTick++;
			if (_playerTick >= player.energyRecoverInternal){
				player.autoRecoverEnergy();
				_playerTick = 0;
			}
			if (_aiTick >= ai.energyRecoverInternal){
				ai.autoRecoverEnergy();
				_aiTick = 0;
			}
		}
	}
}